// router.js
import {
	RouterMount,
	createRouter
} from 'uni-simple-router';
const router = createRouter({
	platform: process.env.VUE_APP_PLATFORM,
	routes: [...ROUTES]
})
// 路由白名单
const whiteList = ['/pages/login/index']
//全局路由前置守卫
router.beforeEach((to, from, next) => {
	if (uni.getStorageSync('token')) {
		if (to.path === '/pages/login/index') {
			next({
				path: '/pages/home/index'
			})
		} else {
			next()
		}
	} else {
		if (whiteList.indexOf(to.path) !== -1) {
			next()
		} else {
			next({
				path: '/pages/login/index'
			})
		}
	}
})

export {
	router,
	RouterMount
}